package com.jrzh.mvc.controller.sys.ajax;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jrzh.common.utils.VerifyCodeUtils;
import com.jrzh.framework.base.controller.BaseAjaxController;
import com.jrzh.framework.contants.GeneralConstant;
import com.jrzh.mvc.service.sys.manage.SysServiceManage;

@Controller(VerifyCodeController.LOCATION + "VerifyCodeController")
@RequestMapping(VerifyCodeController.LOCATION)
public class VerifyCodeController extends BaseAjaxController{
	public static final String LOCATION = "/sys/ajax/verify";
	
	@Autowired
	SysServiceManage sysServiceManage;
	
	@RequestMapping(method=RequestMethod.GET, value="getVerifyCode")
	@ResponseBody
	public void getVerifyCode(){
		//生成随机字串  
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
        try {
        	String sessionCode = request.getParameter("session_code");
        	if(StringUtils.isBlank(sessionCode)){
        		request.getSession().setAttribute(GeneralConstant.SESSION_KEY.VERIFY_CODE, verifyCode);
        	}else{
        		request.getSession().setAttribute(sessionCode, verifyCode);
        	}
        	VerifyCodeUtils.outputImage(200, 80, response.getOutputStream(), verifyCode);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void setData() {
		
	}
}
